<template>
    <a-modal
        title=""
        :visible="true"
        width="40%"
        :footer="null"
        dialogClass="custom-modal"
        :maskClosable="false"
        @cancel="closeStopModal"
    >
        <a-form-model
            :model="stopForm"
            ref="stopForm"
            :rules="stopRules"
            :colon="false"
            class="m-form-model"
            labelAlign="left"
            layout="vertical"
        >
            <a-row :gutter="10">
                <a-col :span="24" class="mb16">
                    <a-form-model-item label="终止授牌原因" prop="jsonRecord">
                        <a-checkbox-group v-model="stopForm.jsonRecord" :disabled="!isEdit">
                            <a-row>
                                <a-col :span="24" class="mb10" v-for="(checkItem, index) in stopCheckList" :key="index">
                                    <a-checkbox :value="checkItem.value" name="type" style="color: #243144">
                                        {{ index + 1 + '.' + checkItem.label }}
                                    </a-checkbox>
                                </a-col>
                            </a-row>
                        </a-checkbox-group>
                    </a-form-model-item>
                </a-col>
            </a-row>
        </a-form-model>
        <div class="h-end-center" v-if="isEdit">
            <a-button @click="closeStopModal" class="mr20">取消</a-button>
            <a-popconfirm title="请确认是否终止授牌" ok-text="是" cancel-text="否" @confirm="chePai">
                <a-button :loading="stopModalLoading" class="mr20" type="primary">确定</a-button>
            </a-popconfirm>
        </div>
        <div class="h-end-center" v-else>
            <a-button @click="closeStopModal" class="mr20">确定</a-button>
        </div>
    </a-modal>
</template>

<script>
import { zzspList } from '@/views/applyManage/config.js'
import { checkApi, getReason } from '@/common/api/applyManage'
import Bus from '@/common/bus.js'
import { getFileToken } from '@/common/api/common'
import url from '@/common/url-config.js'

export default {
    props: {
        record: {
            required: true,
            type: Object,
        },
        isEdit: {
            type: Boolean,
        },
        zzOrCp: {},
    },
    data() {
        return {
            fileType: '.pdf',
            uploadFileUrl: url.uploadFile,
            fileToken: '',

            stopModalLoading: false,
            stopCheckList: zzspList,
            stopForm: {
                jsonRecord: [],
                // archive: null,
            },
            stopRules: {
                jsonRecord: [
                    {
                        required: true,
                        message: '请至少选择一条终止理由',
                    },
                ],
                // archive: [
                //     {
                //         required: true,
                //         message: '请上传证明材料',
                //     },
                // ],
            },
        }
    },
    mounted() {
        setTimeout(() => {
            this.init()
        }, 100)
    },
    methods: {
        async init() {
            Bus.$emit('loadingStateChange', true)
            try {
                let params = {
                    id: this.record.id,
                    state: this.record.cjzt,
                }
                let res = await getReason(params)
                if (res.code == 200 && res.data) {
                    let obj = JSON.parse(res.data)
                    this.stopForm = obj
                }
            } catch (e) {
                console.log(e)
            }
            Bus.$emit('loadingStateChange', false)
        },
        async chePai() {
            this.$refs.stopForm.validate(async valid => {
                if (valid) {
                    this.stopModalLoading = true
                    let params = {
                        jsonRecord: JSON.stringify(this.stopForm),
                        id: this.record.id,
                    }
                    try {
                        let res = await checkApi.revoke(params)
                        if (res.code == 200) {
                            this.$message.success(res.message)
                            this.closeStopModal('reset')
                        }
                    } catch (e) {
                        console.log(e)
                    }
                    this.stopModalLoading = false
                }
            })
        },
        closeStopModal(type = null) {
            this.$emit('close', type)
        },
    },
}
</script>

<style lang="scss" scoped></style>
